﻿using System;
using System.ComponentModel.DataAnnotations;

using MSAcademic.v2.Infrastructure.AccessRights;
using MSAcademic.v2.Infrastructure.Gallery;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Areas.Admin.Models.Gallery
{
    public partial class EditGalleryViewModel
    {
        public int GalleryId { get; set; }

        [Required(ErrorMessage = "Polje ne smije biti prazno!")]
        public string GalleryName { get; set; }
        public bool GalleryIsHidden { get; set; }

        public string Url { get; set; }
        public string ErrorMessage { get; set; }
        
    }

    public partial class EditGalleryViewModel
    {
        public IGallery Gallery
        {
            get
            {
                if (_gallery == null)
                {
                    _gallery = new Lazy<IGallery>(() => _galleryQueries.GetGallery(this.GalleryId));
                }
                return _gallery.Value;
            }
        }
        private Lazy<IGallery> _gallery;
    }

    public partial class EditGalleryViewModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;

        public bool CanUpdate
        {
            get
            {
                if (_canUpdate == null)
                {
                    _canUpdate = new Lazy<bool>(() => 
                        this.SignedInUser != null
                        && (_accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.CanUpdate) 
                        || _accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.CanUpdateAll)));
                }
                return _canUpdate.Value;
            }
        }
        private Lazy<bool> _canUpdate;
    }

    public partial class EditGalleryViewModel
    {
        private readonly ILoginService _loginService;
        private readonly IAccessRightsService _accessRightsService;
        public IGalleryQueries _galleryQueries { get; set; }

        public EditGalleryViewModel(IGalleryQueries galleryQueries,
            ILoginService loginService,
            IAccessRightsService accessRightsService)
        {
            _loginService = loginService;
            _accessRightsService = accessRightsService;
            _galleryQueries = galleryQueries;
        }

        public EditGalleryViewModel()
        {
            
        }

    }
}